package chapter8JVM_excute;

import java.lang.invoke.*;

//使用methodHandler进行调用
public class P83_5 {
     class GrandFather{
        public void talking() throws Throwable {
            System.out.println("GrandFather talking");
        }

    }
     class Father extends GrandFather{
        public void talking() throws Throwable {
            System.out.println("Father talking");
        }
    }

     class Son extends Father{
        public void talking() throws Throwable {
            MethodType methodType = MethodType.methodType(void.class);
            MethodHandle methodHandle = MethodHandles.lookup().findSpecial(GrandFather.class,
                    "talking",methodType,getClass());
            methodHandle.invoke(this);
        }
    }
    public static void main(String[] args) throws Throwable {
        (new P83_5().new Son()).talking();
    }
}
